#pragma once

#include <iostream>
#include <streambuf>
#include <string>

#include <QTextEdit>

class QRedirectStream : public QObject, public std::basic_streambuf<char>
{
	Q_OBJECT

public:
	QRedirectStream(std::ostream &stream, QTextEdit* text_edit);
	
	~QRedirectStream();
	
protected:
	int overflow(int_type v);
	
	std::streamsize xsputn(const char *p, std::streamsize n);	

signals:
	void sendString(const QString& str);

private:
	std::ostream   &m_stream;
	std::streambuf *m_buf;
	std::string     m_string;

	QTextEdit *logWindow;
};
